Firstly, what is NGINX (pronounced as Engine-X)?
NGINX is an open source web server known for its high performance, stability, rich feature set, simple configuration and low resource consumption. Created by Igor Sysoev, the first public release was in 2004 (En.wikipedia.org, n.d.).
NGINX operates in modules and has two different types: core (native) and third-party (external).
- The core modules are built by the core NGINX developers and they are bundled as part of the software itself.
- Third-party modules are built by the NGINX community, these third-party modules are used to extend the functionality of NGINX. Over a hundred third-party modules are currently available. Notable among the third-party modules is the RTMP module developed by Roman Arutyunyan which is used to enable the streaming capabilities of NGINX.
There are two main types of NGINX.
- NGINX Open Source (nginx.org)
- NGINX Plus (nginx.com)
Compiling and Installing NGINX with RTMP Module for media streaming.
Now, let's walk through a step by step guide on how to compile and install NGINX with RTMP module.
Before NGINX can be installed, an operating system on the target machine is needed. This can either be a cloud platform or a local PC with any OS of choice.
For this exercise, a VM instance with Ubuntu 18.04 on Google Cloud Platform is used.
A GCP dashboard showing the streaming media VM instance |
N: B - Various deployment of different types of media streaming servers were carried out as part of the practical exercise in this module, check my previous post (EXERCISE: Deploying Streaming Servers).
So, with the operating system in place, we are ready to get the NGINX complied and installed.
Compiling NGINX from source offers a lot more flexibility and allows third-party modules to be added during the installation.
Full documentation is available online on how to compile NGINX from source. https://docs.nginx.com/nginx/admin-guide/installing-nginx/installing-nginx-open-source/#sources
NGINX requires 3 main dependencies for the default build configuration. These 3 libraries need to be installed first, before NGINX. they are;
- OpenSSL (or LibreSSL or BoringSSL) - Required by the NGINX SSL module and others.
- Zlib - Required by the NGINX Gzip module.
- PCRE - Required by the NGINX Core and Rewrite modules.
Installation procedures
- Update the operating system packages
sudo apt update && sudo apt upgrade
- Install a compiler tool for the operating system
sudo apt install build-essential git libpcre3 libpcre3-dev libssl-dev libperl-dev
- Install NGINX Dependencies
wget http://www.openssl.org/source/openssl-1.1.1b.tar.gz
tar -zxf openssl-1.1.1b.tar.gz
cd openssl-1.1.1b
./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl
make
sudo make install
# Zlib
wget http://zlib.net/zlib-1.2.11.tar.gz
tar -zxf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure
make
sudo make install
# PCRE
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.42.tar.gz
tar -zxf pcre-8.42.tar.gz
cd pcre-8.42
./configure
make
sudo make install
- Clone nginx-rtmp-module
git clone https://github.com/sergey-dryabzhinsky/nginx-rtmp-module.git
- Download NGINX source files
wget http://nginx.org/download/nginx-1.15.10.tar.gz
tar zxf nginx-1.15.10.tar.gz
cd nginx-1.15.10
- Configure the NGINX build.
./configure --with-http_ssl_module --add-module=../nginx-rtmp-module
- Compile and install NGINX
make
sudo make install
- Install the NGINX init scripts to start on boot
sudo wget https://raw.github.com/JasonGiedymin/nginx-init-ubuntu/master/nginx -O /etc/init.d/nginx
sudo chmod +x /etc/init.d/nginx
sudo update-rc.d nginx defaults
- After the installation is finished, start NGINX Open Source
sudo service nginx start
- Create the folder structures necessary to hold the HLS & DASH manifests and video fragments:
sudo mkdir /tmp/hls
sudo mkdir /tmp/dash
- Open and edit the NGINX configuration file according to your requirements
sudo nano /usr/local/nginx/conf/nginx.conf
“live on” turns on live mode.
HLS and DASH should also be ON for HTTP streaming.
The image below shows an example of a config file with the live mode, HLS and DASH turned ‘ON’
- OPTIONAL: Install FFmpeg
sudo apt install ffmpeg
- Clean up all .tar.gz files.
rm -rf *.tar.gz
Post a Comment